<?php

function contains($point, $polygon) {
    if ($polygon[0] != $polygon[count($polygon) - 1]) {
        $polygon[count($polygon)] = $polygon[0];
    }
    $j = 0;
    $oddNodes = false;
    $x = $point[1];
    $y = $point[0];
    $n = count($polygon);
    for ($i = 0; $i < $n; $i++) {
        $j++;
        if ($j == $n) {
            $j = 0;
        }
        if ((($polygon[$i][0] < $y) && ($polygon[$j][0] >= $y)) || (($polygon[$j][0] < $y) && ($polygon[$i][0] >=
                $y))) {
            if ($polygon[$i][1] + ($y - $polygon[$i][0]) / ($polygon[$j][0] - $polygon[$i][0]) * ($polygon[$j][1] -
                    $polygon[$i][1]) < $x) {
                $oddNodes = !$oddNodes;
            }
        }
    }
    return $oddNodes;
}

$polygon = [
    [-12.040369840685711, -77.01149940490723], [-12.043853431333742, -77.01441764831543], [-12.0474209170896, -77.01235771179199], [-12.047169096120564, -77.00785160064697], [-12.042468394679828, -77.00639247894287]
];

$point1 = [-12.043668766036483, -77.00949316387937];
//echo $polygon;
echo contains($point1, $polygon) ? 
        'IN' 
        : 
        'OUT';

